package com.huawei.appmarket.service.appdetail.view.card;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout.LayoutParams;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.widget.MultiLineLabelLayout;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailLabelBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailLabelBean.DetailLabel;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.List;
import o.azb;
import o.cil;
import o.cim.a;
import o.cjk;
import o.cjm;
import o.cjo;
import o.ckt;
import o.djc;
import o.Logger;
import o.ContentManager;
import o.drl;
import o.ewm.d;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class DetailLabelCard extends drl implements OnClickListener {
    private TextView ʻ;
    private DetailLabelBean ʼ;
    private LayoutInflater ʽ;
    private MultiLineLabelLayout ॱॱ;

    public DetailLabelCard() {
        this.ॱ = 308;
    }

    public View ˊ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ʽ = layoutInflater;
        this.ˊ = layoutInflater.inflate(h.ˏˎ, null);
        azb.ˏ(this.ˊ, j.ʾꜟ);
        this.ॱॱ = (MultiLineLabelLayout) this.ˊ.findViewById(j.ॱﹺ);
        azb.ˋ(this.ॱॱ);
        this.ʻ = (TextView) this.ˊ.findViewById(j.ʼﾞ);
        this.ʻ.setText(ContentManager.getInstant().getContext().getResources().getString(n.ㆍॱ));
        this.ॱॱ.ˏ = (int) ContentManager.getInstant().getContext().getResources().getDimension(d.ˎˎ);
        return this.ˊ;
    }

    public boolean ˊ(List<JsonBean> list) {
        if (list == null || list.size() <= 0) {
            return false;
        }
        this.ʼ = (DetailLabelBean) list.get(0);
        if (this.ʼ == null || this.ʼ.ॱ() == null || this.ʼ.ॱ().size() <= 0) {
            return false;
        }
        int size = this.ʼ.ॱ().size();
        int defaultColor = this.ʻ.getTextColors().getDefaultColor();
        for (int i = 0; i < size; i++) {
            View inflate = this.ʽ.inflate(h.ˑ, null);
            inflate.setLayoutParams(ˏ(inflate, i, size));
            ToggleButton toggleButton = (ToggleButton) inflate.findViewById(j.ˈـ);
            toggleButton.setText(((DetailLabel) this.ʼ.ॱ().get(i)).ˊ());
            toggleButton.setTextOn(((DetailLabel) this.ʼ.ॱ().get(i)).ˊ());
            toggleButton.setTextOff(((DetailLabel) this.ʼ.ॱ().get(i)).ˊ());
            toggleButton.setId(j.ॱᵢ + i);
            toggleButton.setOnClickListener(new ckt(this));
            toggleButton.setTextColor(defaultColor);
            this.ॱॱ.addView(inflate);
        }
        return true;
    }

    public LayoutParams ˏ(View view, int i, int i2) {
        LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LayoutParams(-2, -2);
        }
        layoutParams.bottomMargin = ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(d.ॱˋ);
        return layoutParams;
    }

    public void onClick(View view) {
        int id = view.getId();
        int size = this.ʼ.ॱ().size();
        id -= j.ॱᵢ;
        if (id < 0 || id >= size) {
            Logger.e("DetailLabelCard", "list index out of bounds!");
            return;
        }
        DetailLabel detailLabel = (DetailLabel) this.ʼ.ॱ().get(id);
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        appDetailActivityProtocol.ˏ(new Request(detailLabel.ˎ(), detailLabel.ˏ()));
        cjm o_cjm = new cjm("appdetail.activity", appDetailActivityProtocol);
        cil.ˋ(ContentManager.getInstant().getContext(), new a().ˊ(detailLabel.ˎ()).ˋ());
        try {
            List runningTasks = ((ActivityManager) ContentManager.getInstant().getContext().getSystemService("activity")).getRunningTasks(1);
            if (!(runningTasks == null || runningTasks.isEmpty())) {
                RunningTaskInfo runningTaskInfo = (RunningTaskInfo) runningTasks.get(0);
                if (runningTaskInfo != null && runningTaskInfo.numActivities > djc.ˋ() && runningTaskInfo.topActivity.getClassName().equals(this.ˎ.ॱˋ().getClass().getName())) {
                    o_cjm.ॱ(this.ˎ.ॱˋ()).setFlags(HwAccountConstants.FLAG_TRANSLUCENT_STATUS);
                }
            }
        } catch (Throwable e) {
            Logger.ˋ("DetailLabelCard", "onClick error", e);
        }
        cjk.ˎ().ˋ(this.ˎ.ॱˋ(), o_cjm);
    }
}
